package com.his.dictitem.controller;

import com.his.config.annotation.CurrentUser;
import com.his.dictitem.service.DictItemServcie;
import com.his.dictitem.vo.DictItemSearchVo;
import com.his.dictitem.vo.DictItemVo;
import com.his.dictitem.vo.DictItem_DetailedVo;
import com.his.login.entity.DictEmployee;
import com.xiao.common.controller.ResultBaseController;
import com.xiao.common.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
* 项目控制类
* @Author tansonglin
* @Date 2020/3/13
 */
@RestController
@RequestMapping(value="/api/dict_item")
public class DictItemController extends ResultBaseController {

    private  final Logger logger = (Logger) LoggerFactory.getLogger(this.getClass());

    @Autowired
    private DictItemServcie dictItemServcie;

    /**
     *获取项目信息  用作首页显示
     * @param dictItemSearchVo 过滤信息 （选中的目录 、搜索框输入信息、停用标志 ）
     */
    @PostMapping(value="/query_for_main_show.do")
    public ResultUtil getItemForMainShow(@CurrentUser DictEmployee dictEmployee, @RequestBody DictItemSearchVo dictItemSearchVo){
        try {
            return this.success("成功",dictItemServcie.queryForMainShow(dictEmployee,dictItemSearchVo));
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    /**
     *获取项目的详细关联信息
     *  属性信息，价格列表，单位列表
     */
    @GetMapping(value="/query_item_detailed.do")
    public ResultUtil getDetailedItem(@CurrentUser DictEmployee dictEmployee,String itemid){
        try {
            return this.success("成功",dictItemServcie.queryDetailedItem(itemid));
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
    /**
     *插入项目信息
     *  项目主表
     *  项目属性表
     *  项目价格表
     *  项目单位表
     */
    @PostMapping(value="/insert.do")
    public ResultUtil insertItem(@CurrentUser DictEmployee dictEmployee,@RequestBody DictItem_DetailedVo dictItemDetailedVo){
        try {
            dictItemServcie.insertItem(dictEmployee,dictItemDetailedVo);
            return this.success("成功",null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
}
